@model dynamic

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>title</title>
    <script src="/lib/jquery/dist/jquery.min.js"></script>
    <link href="/miniui/themes/default/miniui.css" type="text/css" rel="stylesheet" />
    <link href="/miniui/themes/icons.css" type="text/css" rel="stylesheet" />
    <link href="/miniui/themes/bootstrap/skin.css" type="text/css" rel="stylesheet" />
    <script src="/miniui/miniui.js"></script>
    <script src="/js/axios.js"></script>
</head>
<body>
<div>
    <h1>文章信息管理</h1>

    <div style="padding-bottom:5px;">

        <span>文章标题：</span><input type="text" id="title" />
        <span>文章作者：</span><input type="text" id="author" />
        <input type="button" value="查找" onclick="search()" />

    </div>
    <div style="width:800px;">
        <div class="mini-toolbar" style="border-bottom:0;padding:0;">
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
                        <a class="mini-button" iconCls="icon-remove" onclick="remove()">删除</a>
                        <a class="mini-button" iconCls="icon-ok" onclick="createAllHtml()">一站静态化</a>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div id="datagrid1" class="mini-datagrid" style="width:60%;height:550px;" ajaxType="get" url="/article/getArticles"
         idField="id" allowResize="true"
         sizeList="[2,5,10,30]" pageSize="2"
         showHeader="true" title="文章信息"
         multiSelect="true"
         allowCellEdit="true" allowCellSelect="true"
         onmouseup="return datagrid1_onmouseup()">
        <div property="columns">
            <div type="indexcolumn"></div>
            <div type="checkcolumn"></div>
            <div field="id" width="120" headerAlign="center">编号</div>
            <div field="title" width="120" headerAlign="center">文章标题</div>
            <div field="categoryName" align="right" width="100">文章类别</div>
            <div field="author" width="100" allowSort="true">文章作者</div>
            <div field="origin" width="100" headerAlign="center">文章来源</div>
            <div field="createTime" width="100" headerAlign="center">发布时间</div>
            <div name="action" width="120" headerAlign="center" align="center" cellStyle="padding:0;"  renderer="onActionRenderer" >操作</div>
        </div>
    </div>
    <script>
        mini.parse();

        let grid = mini.get("datagrid1");

        grid.load();
        // 添加
        function add(){
            mini.open({
                targetWindow: window,

                url:"/article/showAdd",
                title: "新增文章", width: 800, height: 700,
                onload: function () {
                    // var iframe = this.getIFrameEl();
                    //var data = { action: "new" };
                    //iframe.contentWindow.SetData(data);
                },
                ondestroy: function () {

                    grid.reload();
                }
            });
        }
        // 构建访问静态页面的链接地址
        function onActionRenderer(e) {
            console.log("e==",e);
            const record = e.record;
            const articleId = record.id;
            return `<a href='/ArticleHtml/${articleId}.html' target="_blank">详情</a>`

        }

        // 一站静态化
        function createAllHtml(){
            if(confirm("这个操作比较耗时,你确定?")){
                axios({
                    method:"post",
                    url:"/article/CreateStaticHtmlForAllArticles"
                }).then(function({data:res}){
                    if(res.code===200){
                        alert(res.msg);
                    }
                })
            }
        }
    </script>
</div>
</body>
</html>